<template>
  <div>
    <template v-if="$cfg.user?.uid == null">
      <n-h3>请登录后申请攻略管理组</n-h3>
      <n-button @click="$cfg.loginif = true" >登录账号</n-button>
    </template>

    <template v-else>
      <n-h3>坎公区攻略管理组 申请表</n-h3>
      <n-form label-placement="left" label-width="auto">
        <n-form-item :label-style="val.labelstyle" label="坎公圈名字：">
          <n-input v-model:value="val.qs.name" placeholder="Input" />
        </n-form-item>
        <n-form-item :label-style="val.labelstyle" label="你的 QQ 号：">
          <n-input v-model:value="val.qs.qq" placeholder="Input" />
        </n-form-item>
        <n-form-item :label-style="val.labelstyle" label="账号UID：">
          <n-input :value="val.qs?.uid ?? '未登录'" placeholder="Input" />
        </n-form-item>
        <n-form-item :label-style="val.labelstyle" label="账号名称：">
          <n-input :value="val.qs?.username ?? '未登录'" placeholder="Input" />
        </n-form-item>
      </n-form>
      <n-space>
        <n-button type="warning" @click="ct.click_adg()">确认申请</n-button>
        <n-button @click="val.md_adg = false">关闭窗口</n-button>
      </n-space>
    </template>

  </div>
</template>

<script>
import axios from "axios";
import { cfg } from "@/cfg/cfg.js";

export default {
  mounted() {
    this.val.md_adg_loading = false;
  },
  props: {
    val: {
      type: Object,
      required: true,
    },
    ct: {
      type: Object,
      required: true,
    },
  },
  setup(props) {

    //加载msg组件
    if (cfg.msg == undefined) {
      cfg.msg = useMessage();
    }

    let ct = props.ct;
    let val = props.val;
    ct.click_adg = () => {
      val.md_adg_loading = true;

      axios.get(`${cfg.url}`, {
            params: {
              t: "get/Introduction/new_adg",
              data : val.qs,
              authkey: cfg.user?.authkey,
            },
          })
          .then((res) => {
            const data = res.data;
            cfg.msg.success(`${data.msg}`, { duration: 2e3 });
            val.md_adg_loading = false;
            if(data.code == 0){
              val.md_adg = false
            }
          })
          .catch((err) => {
            alert(err);
          });

    };
  },
};
</script>
